package com.gmail.blackdog1987.onedollar.dao;

import com.gmail.blackdog1987.onedollar.dao.hibernate.EntityHibernateDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.BaseJdbcDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.JdbcUtil;
import com.gmail.blackdog1987.onedollar.entity.AppAdEntity;
import com.gmail.blackdog1987.onedollar.entity.TOrderOnedollarUserEntity;
import com.gmail.blackdog1987.onedollar.entity.base.Page;
import com.gmail.blackdog1987.onedollar.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository("orderOneDollarUserDao")
public class OrderOneDollarUserDao extends EntityHibernateDao<TOrderOnedollarUserEntity>{
    @Autowired
    private BaseJdbcDao baseJdbcDao;
    public Page<TOrderOnedollarUserEntity> queryForPage(int pageindex, int pagesize, int onedollarid){

        String limit = " limit " + (pageindex-1)*pagesize + "," + pagesize;
        Integer totalCount = baseJdbcDao.getJdbcTemplate().queryForInt(" SELECT COUNT(*) from t_order_onedollar_user where onedollar_id = ? order by createtime desc" , new Object[]{onedollarid});

        List<TOrderOnedollarUserEntity> list = JdbcUtil.queryForList(baseJdbcDao, TOrderOnedollarUserEntity.class, "SELECT * from t_order_onedollar_user where onedollar_id = ? order by createtime desc " + limit, new Object[]{onedollarid});

        Page page = new Page(list, pageindex, totalCount, pagesize);

        return page;
    }
}
